﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using devtm.Editor.Configuration.Data;
using devtm.Helpers.Factories;

namespace devtm.Editor.Configuration
{
    /// <summary>
    /// Interaction logic for LstBox.xaml
    /// </summary>
    public partial class LstBox : UserControl
    {
        public LstBox()
        {
            InitializeComponent();
        }

        public ConfigPropertiesCollection LoadConfig(ElementSection section)
        {

            ConfigPropertiesCollection Properties = null;

            if (section != null && section.ConfigurationElement != null)
                Properties = new ConfigPropertiesCollection(section);

            DataContext = Properties;

            return Properties;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RunEditor(object sender, RoutedEventArgs e)
        {
            ConfigProperty editor = ((sender as Button).Tag as ConfigProperty);
            editor.RunEditor();
        }


        private void Validator(object sender, TextChangedEventArgs e)
        {
            ConfigProperty editor = ((sender as TextBox).Tag as ConfigProperty);
            editor.Validator((sender as TextBox).Text);
        }


        //private void Button_Add(object sender, RoutedEventArgs e)
        //{

        //}


        //private void Button_Del(object sender, RoutedEventArgs e)
        //{

            //if (MessageBox.Show("Are you sure you want remove this item ?", "", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.Yes) == MessageBoxResult.Yes)
            //{
            //    ConfigProperty editor = ((sender as Button).Tag as ConfigProperty);
            //    editor.RunDel();
            //}
        //}

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            if (e.AddedItems.Count > 0)
            {
                ComboBox c = (sender as ComboBox);
                TemplateListeSelector template = (TemplateListeSelector)c.Tag;

                template.Value = ((Facad)e.AddedItems[0]).Property1;

            }
            
        }

        private void SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            if (SelectionChangedEventHandler != null)
                SelectionChangedEventHandler(sender, e);
        }

        public event EventHandler<SelectionChangedEventArgs> SelectionChangedEventHandler;


    }
}
